class Solution {
public:
    int pivotIndex(vector<int>& nums) {

        int sum_left = 0;
        int sum = 0;

        if(nums.size() == 0)
            return -1;
        
        for(int i = 0; i < nums.size(); i++)
        {
            sum = sum + nums[i];
        }

        if(sum - nums[0] == 0)
            return 0;

        for(int j = 0; j < nums.size() - 1; j++)
        {  
            sum_left = sum_left + nums[j];

            if(sum_left * 2 + nums[j + 1] == sum)
            {
                return j + 1;
                break;
            }            
        }

        if(sum - nums[nums.size() - 1] == 0)
            return nums.size() - 1;
        else return -1;
        
    }
};

// The same question, the different answer 